package com.dreamer.service.lottery;

import com.dreamer.domain.lottery.Activity;
import com.dreamer.repository.lottery.ActivityDAO;
import org.hibernate.query.Query;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ps.mx.otter.utils.SearchParameter;

import java.util.List;

@Service
public class ActivityHandler {

    @Autowired
    private ActivityDAO activityDAO;

    @Transactional
    public Activity saveOrupdate(Activity activity){
        Activity instance = activityDAO.merge(activity);
        LOG.debug("新增活动成功"+instance);
        return activity;
    }

    @Transactional
    public void removeActivity(Activity activity) {
        activityDAO.delete(activity);
        LOG.debug("删除活动成功");
    }

    private final Logger LOG = LoggerFactory.getLogger(getClass());

    public Activity findById(Integer integer) {
        return  activityDAO.findById(integer);
    }

    public List<Activity> searchAllByPage(SearchParameter<Activity> parameter) {
        return activityDAO.searchAllByPage(parameter);
    }

    public List<Activity> findAll(){
        return activityDAO.findAll();
    }

}
